package com.wuyan.web.auth.config;

import com.wuyan.web.base.helper.MappingJackson2HttpMessageTextPlainConverter;
import feign.codec.Decoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Bean配置
 *
 * @author wuyan
 */

@Configuration
public class AuthBeanConfig {

    /**
     * 增加返回参数为[text/plain] 类型的JSON解析
     *
     * @return Decoder
     */
    @Bean
    public Decoder feignDecoder() {
        MappingJackson2HttpMessageTextPlainConverter converter = new MappingJackson2HttpMessageTextPlainConverter();
        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter);
        return new SpringDecoder(objectFactory);
    }
}
